<template>
  <el-container>
    <el-aside :style="asideStyle">
      <navbar :menus="menus" :collapse="isCollapse"></navbar>
    </el-aside>

    <el-container>
      <el-header>
        <el-button type="info" class="infobutton" @click="handleCollapse">
          <svg class="icon" aria-hidden="true" :class="iconDeg">
            <use xlink:href="#icon-icon_more2" />
          </svg>
        </el-button>
        <!-- <i
            :class="iconDeg"
            class="el-icon-s-fold"
            @click="handleCollapse" 
        ></i>-->

        <svg class="icon1" aria-hidden="true" @click="Logout">
          <use xlink:href="#icon-tubiaozhizuomoban-" />
        </svg>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Navbar from "./Navbar";
import routes from "../router/routes";
import { clearToken } from "../utils/auth";
export default {
  data() {
    return {
      isCollapse: false,
    };
  },
  methods: {
    handleCollapse() {
      this.isCollapse = !this.isCollapse;
    },
    //路由菜单
    resolveForMenu(arr, parentPath = "") {
      let newArr = [];
      // 遍历传入的arr数组

      // 处理上级路径

      //判断当前对象（路由）是否具有children节点，如果有，递归处理children节点后，
      //将当前节点加入数组，，如果没有则直接将当前节点加入新数组

      //返回最后处理完成的数组

      arr.forEach((route) => {
        parentPath =
          parentPath && parentPath.lastIndexOf("/") !== parentPath.length - 1
            ? parentPath + "/"
            : parentPath;
        // console.log(parentPath);
        let obj = Object.assign({}, route);
        obj.path = parentPath + obj.path;
        if (obj.children && obj.children.length > 0) {
          obj.children = this.resolveForMenu(obj.children, obj.path);
        }
        // 如果某路由元数据中，设置为当前路由为隐藏，则当前路由将不作为导航菜单显示，只将其children加入到菜单数组
        if (obj.meta.hidden) {
          //判断是否有children,有则加入判断hidden，没有则加入数组
          if (obj.children && obj.children.length > 0) {
            obj.children.forEach((item) => {
              let tmp = Object.assign({}, item);
              newArr.push(tmp);
            });
          }
        } else {
          newArr.push(obj);
        }
      });

      return newArr;
    },
    Logout() {
      console.log("注销");
      clearToken();
      this.$router.push("/loginBack");
    },
  },
  components: {
    Navbar,
  },
  computed: {
    menus() {
      let arr = this.resolveForMenu(routes);

      return arr;
    },
    asideStyle() {
      return {
        width: this.isCollapse ? "0px" : "220px",
      };
    },
    iconDeg() {
      return {
        "icon-deg": this.isCollapse ? true : "",
      };
    },
  },
};
</script>

<style scoped>
body {
  background-color: rgb(236, 236, 236);
  margin: 0px !important;
  color: white;
}
.icon-deg {
  transform: rotate(-90deg);
}
.icon {
  width: 15px;
}

.el-header {
  /* background-color: #b3c0d1;
  color: #333; */
  text-align: center;
  line-height: 12vh;
}

.el-header {
  display: flex;
  align-items: center;
  background-color: #0b2a53;
  justify-content: space-between;
  color: white;
}

.el-aside {
  /* background-color: #545c64;
  color: #333; */
  background-color: #02142B ;
  text-align: center;
  line-height: 200px;
  line-height: 60px;
}

.el-main {
  background-color: rgb(236, 236, 236);
  /* background-color: rgb(61, 69, 85); */
  max-height: 90vh;
  padding: 8vh !important;
}
.infobutton {
  width: 40px;
  height: 40px;

  align-items: center;
  justify-content: center;
  display: flex;
}
.icon1 {
  width: 40px;
}
</style>